package net.wofly.sale.stock.service;

import net.wofly.common.persistence.PageWrapper;
import net.wofly.common.util.ReturnBean;
import net.wofly.sale.report.domain.StockDTO;
import net.wofly.sale.stock.domain.InStock;
import net.wofly.sale.stock.domain.OutStock;
import net.wofly.sale.stock.domain.Stock;
import net.wofly.sale.stock.domain.StockWarning;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;

import java.util.List;

/**
 * @author lign
 * @version 1.0
 * @created 11-10月-2017 21:17:41
 */
public interface IStockService {
    
    /**
     * 增加或修改
     *
     * @param entity
     * @return
     */
    public Stock save(Stock entity);
    
    /**
     * 删除
     *
     * @param entity
     * @return
     */
    public void delete(Stock entity);
    
    /**
     * 根据主键ID删除
     *
     * @param key
     * @return
     */
    public void delete(String key);
    
    /**
     * 根据主键查询
     *
     * @param key
     * @return
     */
    public Stock findOne(String key);
    
    public Page<Stock> findAll(Specification specification, Pageable pageable);
    
    public List<Stock> save(List<Stock> entityList);
    
    public Stock findByWarehouseIDAndCommodityTerminalID(String warehouseID, String commodityTerminalID);
    
    public List<Stock> findByWarehouseIDAndNumGreaterThan(String warehouseID, Integer num);
    
    /**
     * @param inStock
     */
    public ReturnBean<InStock> addInStock(InStock inStock);
    
    /**
     * 添加出库
     * <ul>
     * <li>需要校验库存是否达到预警值</li>
     * </ul>
     *
     * @param outStock
     */
    public ReturnBean<OutStock> addOutStock(OutStock outStock);
    
    /**
     * 校验库存
     * <ul>
     * <li>校验库存是否达到预警值，达到预警值时，需要向消息表中写一条记录</li>
     * </ul>
     *
     * @param warehouseID
     * @param commodityTypeID
     * @param commodityChannelID
     */
    public ReturnBean<String> checkStockWarning(String warehouseID, String commodityTypeID, String commodityTerminalID);
    
    /**
     * @param employeeID
     */
    public ReturnBean<PageWrapper<InStock>> getMyInStock(String employeeID,Integer pageNum, Integer pageSize);
    
    /**
     * 获取全部入库流水
     * <ul>
     * <li></li>
     * 
     * 查询全部库存
     * companyOrgID = -1 时，查询公司库存。
     * companyOrgID shopOrgID employeeID 三个值，以此顺序为优先级，第一个有值就查哪个的库存。
     * 
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<InStock>> getAllInStock(String companyOrgID,String shopOrgID, String employeeID, Integer pageNum, Integer pageSize);
    
    
    /**
     * @param employeeID
     */
    public ReturnBean<PageWrapper<OutStock>> getMyOutStock(String employeeID,Integer pageNum, Integer pageSize);
    /**
     * 获取公司出库流水
     * <ul>
     * <li>查找公司所有商品入库流水</li>
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<OutStock>> getCompanyOutStock(String companyID, Integer pageNum, Integer pageSize);
    /**
     * 获取机构出库流水
     * <ul>
     * <li>查找机构商品入库流水</li>
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<OutStock>> getOrgOutStock(String orgID, Integer pageNum, Integer pageSize);
    
    /**
     * 获取全部出库流水
     * <ul>
     * <li></li>
     * 
     * 查询全部库存
     * companyOrgID = -1 时，查询公司库存。
     * companyOrgID shopOrgID employeeID 三个值，以此顺序为优先级，第一个有值就查哪个的库存。
     * 
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<OutStock>> getAllOutStock(String companyOrgID,String shopOrgID, String employeeID, Integer pageNum, Integer pageSize);
    
    
    
    /**
     * 获取我的库存
     * <ul>
     * <li>根据传递过来的用户关联仓库查相应的库存</li>
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<Stock>> getMyStock(String employeeID, Integer pageNum, Integer pageSize);
    
    /**
     * 获取公司库存
     * <ul>
     * <li>查找公司所有商品库存</li>
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<Stock>> getCompanyStock(String companyID, Integer pageNum, Integer pageSize);
    
    /**
     * 获取公司入库流水
     * <ul>
     * <li>查找公司所有商品入库流水</li>
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<InStock>> getCompanyInStock(String companyID, Integer pageNum, Integer pageSize);
    
    /**
     * 获取机构入库流水
     * <ul>
     * <li>查找机构商品入库流水</li>
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<InStock>> getOrgInStock(String orgID, Integer pageNum, Integer pageSize);
    
    /**
     * 获取机构库存
     * <ul>
     * <li>查找机构商品库存</li>
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<Stock>> getOrgStock(String orgID, Integer pageNum, Integer pageSize);
    
    /**
     * 获取全部库存
     * <ul>
     * <li>根据传递过来的用户关联仓库查相应的库存</li>
     * 
     * 查询全部库存
     * companyOrgID = -1 时，查询公司库存。
     * companyOrgID shopOrgID employeeID 三个值，以此顺序为优先级，第一个有值就查哪个的库存。
     * 
     * <li></li>
     * </ul>
     *
     * @param employeeID
     */
    public ReturnBean<PageWrapper<Stock>> getAllStock(String companyOrgID,String shopOrgID, String employeeID, Integer pageNum, Integer pageSize);
    
    
    
    /**
     * @param warehouseID
     * @param commodityTypeID
     * @param commodityChannelID
     */
    public ReturnBean<PageWrapper<StockWarning>> getStockWarningByPage(String warehouseID, String commodityTypeID,
                                                                       String commodityTerminalID, Integer pageNum, Integer pageSize);
    
    /**
     * @param warehouseID
     * @param commodityTypeID
     * @param commodityChannelID
     * @param num
     */
    public ReturnBean<StockWarning> setStockWarning(String warehouseID, String commodityTypeID, String
    		commodityTerminalID, Integer num);

    List<Stock> findByWarehouseID(String warehouseID);

    /**
     * 查询库存数量
     *
     * @param countDate
     * @param countEndTime
     * @return
     */
    List<StockDTO> findByCountDate(Long countDate, Long countEndTime);
}